import { Body, Controller, Get, HttpCode, HttpException, HttpStatus, Post, Query, UseFilters } from "@nestjs/common";
import { HttpExceptionFilter } from "src/common/filters/http-exception.filter";
import { ExcepitonServer } from "./exception.service";


@Controller('/exception')
@UseFilters(new HttpExceptionFilter())
export class ExcepitonController {
  constructor(private readonly exceptionService: ExcepitonServer){}

  @Get()
  get (@Query(){id}) {
    if (!id) {
      throw new HttpException (
        { status: HttpStatus.BAD_REQUEST, message: '请求参数id 必传', error: 'id is required' },
        HttpStatus.BAD_REQUEST,
      )
    }
    return this.exceptionService.get(id)
  }

  @Post()
  @HttpCode(200)
  post (@Body(){message}) {
    return this.exceptionService.post(message)
  }
}